package translinkApp.Adaptors;

import java.util.ArrayList;

import translinkApp.Data.Journey.Search.JourneySearch;
import translinkApp.Data.Journey.Search.JourneySearchList;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.CheckBox;

public class JourneyAdapter extends BaseAdapter {

	private Context mContext;
	private JourneySearchList journies;
	private ArrayList<CheckBox> checkBoxes;

	public JourneyAdapter(Context c, JourneySearchList locations) {
		this.mContext = c;
		this.journies = locations;
		this.checkBoxes = new ArrayList<CheckBox>();
	}

	public ArrayList<CheckBox> getCheckBoxes() {
		return checkBoxes;
	}

	public int getCount() {

		return journies.size();
	}

	public Object getItem(int position) {
		return journies.get(position);
	}

	public long getItemId(int position) {
		return 0;
	}

	public boolean isChecked(int position) {
		return checkBoxes.get(position).isChecked();
	}

	public View getView(int position, View convertView, ViewGroup parent) {
		CheckBox checkBox;
		if (convertView == null) {
			checkBox = new CheckBox(mContext);
			checkBoxes.add(checkBox);

		} else {
			checkBox = (CheckBox) convertView;
		}

		JourneySearch search = (JourneySearch) getItem(position);
		checkBox.setText(search.getJourneyName());
		checkBox.setTag(search);
		return checkBox;
	}

}
